/*
 * 1069Bermuda.cpp
 *
 *  Created on: 2011-7-21
 *      Author: jfhu
 */

#include <cstdio>
#include <stdio.h>
#include <algorithm>

using namespace std;

const int MAX_TYPES = 10;
const int MAX_LENGTH = 25;
const int MAXIMUM_ROWS = MAX_LENGTH + MAX_LENGTH;
int triangles[MAX_TYPES];
int triangleSides[MAX_TYPES];

// State array used in the dynamic programming procedure <i>checkCombinatin</i>
bool state[MAX_TYPES + 1][MAX_LENGTH + 1];

// The start and end points of triangleSides of each row
// Attention:there are two triangles of triangleSides according to their directions, namely up and down respectively
// 0 indicates down triangleSides, 1 indicates up triangleSides
// The end points should never be reached
int startPoints[MAXIMUM_ROWS][2];
int endPoints[MAXIMUM_ROWS][2];

int hexagonSide, numberOfTriangle;
int rows, columns;

// The status array for each triangle's cover
bool cover[MAXIMUM_ROWS][MAXIMUM_ROWS][2];

// Initializing
void init()
{
	memset(cover, 0, sizeof(cover));
	rows = hexagonSide + hexagonSide;
	for (int i = 0; i < hexagonSide; i++) {
		startPoints[i][0] = startPoints[i][1] = hexagonSide - i;
		endPoints[i][0] = startPoints[i][0] + hexagonSide + i + 1;
		endPoints[i][1] = startPoints[i][1] + hexagonSide + i;
	}

	for (int i = hexagonSide; i < rows; i++) {
		startPoints[i][0] = 1;
		startPoints[i][1] = 0;
		endPoints[i][0] = endPoints[i][1] = rows + i - hexagonSide;
	}

	sort(triangles, triangles + numberOfTriangle);

}

bool isCoverable(int row, int column, int triangleSide, int upOrDown)
{
	for (int i = 0; i < triangleSide; i++) {
		for (int j = (upOrDown - 1) * i; j < upOrDown * (triangleSide - i - 1) + 1; ++j) {
			int r = row + i, c = column + j;
			if (r == rows || c == endPoints[r][upOrDown] || cover[r][c][upOrDown])
				return false;
		}

		for (int j = (upOrDown - 1) * i + upOrDown; j < upOrDown * (triangleSide - i - 1) + upOrDown; ++j) {
			int r = row + i, c = column + j;
			if (r == rows || c == endPoints[r][upOrDown] || cover[r][c][upOrDown])
				return false;
		}
	}

	return true;
}

void doCover(int row, int column, int triangleSide, int upOrDown, int mask)
{
	for (int i = 0; i < triangleSide; i++) {
		for (int j = (upOrDown - 1) * i; j < upOrDown * (triangleSide - i - 1) + 1; ++j) {
			int r = row + i, c = column + j;
			cover[r][c][upOrDown] = mask;
		}

		for (int j = (upOrDown - 1) * i + upOrDown; j < upOrDown * (triangleSide - i - 1) + upOrDown; ++j) {
			int r = row + i, c = column + j;
			cover[r][c][1 - upOrDown] = mask;
		}
	}
}

// Begin search

bool search(int row, int column, int upOrDown)
{
	// What if upOrDown is 1?
	if (column == endPoints[row][upOrDown]) {
		if (row == rows - 1)
			return true;
		if (upOrDown == 0)
			++row;
		return search(row, startPoints[row][1 - upOrDown], 1 - upOrDown);
	}

	if (cover[row][column][upOrDown]) {
		while (column < endPoints[row][upOrDown] && cover[row][column][upOrDown])
			++column;
		return search(row, column, upOrDown);
	}


	for (int i = 0; i < numberOfTriangle; i++) {
		if (!isCoverable(row, column, triangles[i], upOrDown))
			return false;
		doCover(row, column, triangles[i], upOrDown, true);
		if (search(row, column + 1, upOrDown))
			return true;
		doCover(row, column, triangles[i], upOrDown, false);
	}
	return false;
}

// Get the number of unit triangleSides according to side length
int getNumberOfTriangles(int sideLength)
{
	return sideLength * sideLength;
}

// Check the side is times of one side of one triangle
bool checkTimes()
{
	for (int i = 0; i < numberOfTriangle; i++){
		if (hexagonSide % triangles[i] == 0)
			return true;
	}
	return false;
}

// Check whether some combination of integers
// satisfies the <i>sum</i>
bool checkCombination(int numberOfTriangle, int* elements, int sum)
{
	for (int i = 0; i < numberOfTriangle + 1; i++) {
		state[i][0] = true;
	}

	for (int i = 1; i < sum + 1; i++) {
		state[0][i] = false;
	}

	for (int i = 1; i < numberOfTriangle + 1; i++) {
		for (int j = 1; j < sum + 1; j++) {
			state[i][j] = state[i - 1][j];
			if (j >= elements[i - 1]) {
				state[i][j] |= (state[i - 1][j - elements[i - 1]] || state[i][j - elements[i - 1]]);
			}
		}
	}

	return state[numberOfTriangle][sum];
}


int main(int argc, char *argv[])
{
	int numberOfTestCases;
	scanf("%d", &numberOfTestCases);

	while (numberOfTestCases) {
		scanf("%d %d", &hexagonSide, &numberOfTriangle);

		for (int i = 0; i < numberOfTriangle; i++) {
			scanf("%d", triangles + i);
			triangleSides[i] = getNumberOfTriangles(triangles[i]);
		}

		// Stage1
		if (checkTimes()) {
			printf("YES\n");
		}	else {
			if (!checkCombination(numberOfTriangle, triangles, hexagonSide)) {
				printf("NO\n");
			} else if (!checkCombination(numberOfTriangle, triangleSides, 6 * getNumberOfTriangles(hexagonSide))){
				printf("NO\n");
			} else {
				init();
				if (search(0, startPoints[0][1], 1))
					printf("YES\n");
				else
					printf("N0\n");
			}
		}

		--numberOfTestCases;
	}
	return 0;
}




